package com.test.nnooolwdeaer.activity_fragment_wooden;

import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.test.nnooolwdeaer.R;
import com.test.nnooolwdeaer.activity_fragment_wooden.base_wooden.BaseActivity_wooden;
import com.test.nnooolwdeaer.util_wooden.ThreadUtil_wooden;
import com.test.nnooolwdeaer.util_wooden.http_wooden.HttpManager_wooden;
import com.test.nnooolwdeaer.view_wooden.widget_wooden.TitleView_wooden;

import java.util.ArrayList;

public class ServiceFeedbackActivity_wooden extends BaseActivity_wooden {

    private String type_wooden;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_service_feedback_wooden);
        init_wooden();
    }

    private void init_wooden(){

        TitleView_wooden titleView = findViewById(R.id.activity_service_feedback_view_title);
        setBackBtn_wooden(titleView.getBackIb_wooden());

        ArrayList<TextView> typeTvs = new ArrayList<TextView>(){{
            add(findViewById(R.id.activity_service_feedback_tv_product_suggestion));
            add(findViewById(R.id.activity_service_feedback_tv_app_bugs));
            add(findViewById(R.id.activity_service_feedback_tv_payment_issues));
            add(findViewById(R.id.activity_service_feedback_tv_others));
        }};

        for (TextView typeTv1:typeTvs){
            typeTv1.setOnClickListener(v -> {
                for (TextView typeTv2:typeTvs){
                    if (typeTv1==typeTv2){
                        typeTv2.setBackgroundResource(R.drawable.ic_service_feedback_type_true);
                        typeTv2.setTextColor(Color.WHITE);
                        type_wooden = typeTv2.getText().toString();
                    }else {
                        typeTv2.setBackgroundResource(R.drawable.ic_service_feedback_type_false);
                        typeTv2.setTextColor(getColor(R.color.blue_wooden));
                    }
                }
            });
        }

        EditText inputEt = findViewById(R.id.activity_service_feedback_et_input);
        Button submitBtn = findViewById(R.id.activity_service_feedback_btn_submit);

        submitBtn.setOnClickListener(v -> {
            String input = inputEt.getText().toString();
            if (TextUtils.isEmpty(type_wooden)||TextUtils.isEmpty(input)) {
                showToast_wooden(getString(R.string.word_input_tip));
                return;
            }
            HttpManager_wooden.getInstance_wooden().submitServiceFeedback_wooden(type_wooden,input);
        });

    }

    public void onSubmitServiceFeedback_wooden(){
        showToast_wooden(getString(R.string.word_submit_success));
        ThreadUtil_wooden.getInstance_wooden().postDelay_wooden(this::onBackPressed,1000);
    }

}